//
//  ElevenChapterViewController.m
//  CoreAnimation
//
//  Created by 张国文 on 16/11/1.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "ElevenChapterViewController.h"
#import "VectorShapeViewController.h"
#import "DirtyRectanglesViewController.h"

@interface ElevenChapterViewController ()

@end

@implementation ElevenChapterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
    firstButton.frame = CGRectMake(0, 20, 360, 50);
    [firstButton setTitle:@"矢量图形-画图" forState:UIControlStateNormal];
    [firstButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    firstButton.tag = 100;
    [firstButton addTarget:self action:@selector(clickJump:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:firstButton];
    
    UIButton *sectionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    sectionButton.frame = CGRectMake(0, 70, 360, 50);
    [sectionButton setTitle:@"脏矩形" forState:UIControlStateNormal];
    [sectionButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    sectionButton.tag = 101;
    [sectionButton addTarget:self action:@selector(clickJump:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:sectionButton];
    //
    //    UIButton *thirdButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //    thirdButton.frame = CGRectMake(0, 120, 360, 50);
    //    [thirdButton setTitle:@"基于关键帧的缓冲-模拟小球掉落" forState:UIControlStateNormal];
    //    [thirdButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    //    thirdButton.tag = 102;
    //    [thirdButton addTarget:self action:@selector(clickJump:) forControlEvents:UIControlEventTouchUpInside];
    //    [self.view addSubview:thirdButton];
    //
    //    UIButton *progressAutoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //    progressAutoButton.frame = CGRectMake(0, 170, 360, 50);
    //    [progressAutoButton setTitle:@"流程自动化-模拟小球掉落" forState:UIControlStateNormal];
    //    [progressAutoButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    //    progressAutoButton.tag = 103;
    //    [progressAutoButton addTarget:self action:@selector(clickJump:) forControlEvents:UIControlEventTouchUpInside];
    //

    
    UIButton *progressAutoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        progressAutoButton.frame = CGRectMake(0, 170, 360, 50);
        [progressAutoButton setTitle:@"输出按钮" forState:UIControlStateNormal];
    progressAutoButton.backgroundColor = [UIColor cyanColor];
        [progressAutoButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        progressAutoButton.tag = 103;
        [progressAutoButton addTarget:self action:@selector(progress:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:progressAutoButton];
    
    
        UIButton *thirdButton = [UIButton buttonWithType:UIButtonTypeCustom];
        thirdButton.frame = CGRectMake(0, 120, 360, 50);
        [thirdButton setTitle:@"移动" forState:UIControlStateNormal];
        [thirdButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        thirdButton.tag = 102;
        [thirdButton addTarget:self action:@selector(third:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:thirdButton];
    
}

- (void)progress:(UIButton *)button
{
    NSLog(@"输出");
}

- (void)third:(UIButton *)button
{
    UIButton *tempButton = (UIButton *)[self.view viewWithTag:103];
    
    NSLog(@"tempButton改变view的position之前，frame：%@，center：%@，postion：%@，锚点：%@, tempButton的layer的frame：%@", [NSValue valueWithCGRect:tempButton.frame], [NSValue valueWithCGPoint:tempButton.center], [NSValue valueWithCGPoint:tempButton.layer.position], [NSValue valueWithCGPoint:tempButton.layer.anchorPoint],  [NSValue valueWithCGRect:tempButton.layer.frame]);
   
    // 显式动画
//    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
//    animation.duration = 2.0;
//    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(180, 400)];
//    animation.fillMode = kCAFillModeForwards;
//    animation.removedOnCompletion = NO;
//    [tempButton.layer addAnimation:animation forKey:nil];
    // 隐式动画
    [UIView animateWithDuration:2.0 animations:^{
        tempButton.transform = CGAffineTransformMakeTranslation(0, 200);
    }];

    NSLog(@"tempButton改变view的position之后，frame：%@，center：%@，postion：%@，锚点：%@, tempButton的layer的frame：%@", [NSValue valueWithCGRect:tempButton.frame], [NSValue valueWithCGPoint:tempButton.center], [NSValue valueWithCGPoint:tempButton.layer.position], [NSValue valueWithCGPoint:tempButton.layer.anchorPoint],  [NSValue valueWithCGRect:tempButton.layer.frame]);
}

- (void)clickJump:(UIButton *)button
{
    switch (button.tag) {
        case 100:
        {
            VectorShapeViewController *vectorShapeVC = [[VectorShapeViewController alloc] init];
            [self.navigationController pushViewController:vectorShapeVC animated:YES];
            break;
        }
        case 101:
        {
            DirtyRectanglesViewController *dirtyRectanglesVC = [[DirtyRectanglesViewController alloc] init];
            
            [self.navigationController pushViewController:dirtyRectanglesVC animated:YES];
            break;
        }
        case 102:
        {
            
            break;
        }
        case 103:
        {
            
            break;
        }
        default:
            break;
    }
}


@end
